import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../components/MyLogin.vue'
import Hmoe from '../components/MyHome.vue'
import Wcome from '../components/MyWcome.vue'
import User from '../components/user/MyUser.vue'
import Rights from '../components/power/MyRights.vue'
import Roles from '../components/power/MyRoles.vue'
import Cate from '../components/goos/GoodsCate.vue'
import Params from '../components/goos/GoodsPas.vue'
import Glist from '../components/goos/GoodsList.vue'
import Agoods from '../components/goos/AddGoods.vue'
import Order from '../components/order/MyOrder.vue'
import MyReport from '../components/report/MyReport.vue'
Vue.use(VueRouter)

const routes = [
  //重定向
  { path: '/', redirect: '/login' },
  { path: '/login', component: Login },
  {
    path: '/home', component: Hmoe,redirect:'/wcome',
    children: [{ path: '/wcome', component: Wcome },
      {path:'/users',component:User},
      {path:'/rights',component:Rights},
      {path:'/roles',component:Roles},
      {path:'/categories',component:Cate},
      {path:'/params',component:Params},
      {path:'/goods',component:Glist,},
      {path:'/goods/add',component:Agoods},
      {path:'/orders',component:Order},     
      {path:'/reports',component:MyReport},     
    ]
  }
]

const router = new VueRouter({
  routes
})
router.beforeEach((to, from, next) => {
  if (to.path === '/login') return next()
  const tokenstr = window.sessionStorage.getItem('token')
  if (!tokenstr) return next('/login')
  next()
})
export default router
